package com.yoshino.state;

import java.util.Random;

/**
 * 抽奖的状态
 *
 * @author yoshino
 **/
public class CanRaffleState implements State {

    RaffleActivity activity;

    //初始化时传入活动引用，扣除积分后改变其状态
    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }

    // 已经扣除了积分，不能再扣
    @Override
    public void deduceMoney() {
        System.out.println("已经扣除积分");
    }

    // 可以抽奖了
    @Override
    public boolean raffle() {
        System.out.println("正在抽奖");
        Random random = new Random();
        int num = random.nextInt(10);
        //10%中奖机会
        if (num == 0) {
            //改变活动状态为发放奖品
            activity.setState(activity.getDispenseRaffleState());
            return true;
        } else {
            System.out.println("很遗憾没有抽中奖品！");
            //改变状态为不能抽奖
            activity.setState(activity.getNoRaffleState());
            return false;
        }
    }

    @Override
    public void dispensePrize() {
        System.out.println("不能发奖品");
    }
}
